<template>
	<view class="indexs">
		<view class="header header_lan" :style="'padding-top: ' + navH + 'px;'">
			<view class="header_height"
				:style="'height:' + gaodu + 'px;line-height:' + gaodu + 'px;top:' + gaodutops + 'px;'">
				<view class="index_h_cont3">
					<view class="index_wenben_img" @tap="jumpzuo">
						<image :src="imgUrl + '/dzx_img22.png'" mode="widthFix"></image>
					</view>
					<view class="index_wenben baise">{{ $t('page_indexs_dairuku.my_package') }}</view>
				</view>
			</view>
			<view class="coloe_title">s</view>
		</view>
		<view class="index_center" :style="'padding-top:' + (navH + 50) + 'px;'">
			<view class="dairuku_item">
				<view class="cangkuyuan_baoguoliebiao_item2">
					<!-- 1 待入库 2 已入库 3 已上架(提交打包准备)  4 待打包  5 待支付  6 已支付 7 加入批次(扫码入批次了)  8 已打包  9 已发货 10 已收货 11 已完成 -->
					<!-- 1 待入库 -->
					<!-- <view
						:class="dianjis == 1 ? 'cangkuyuan_baoguoliebiao_item2_t1' : 'cangkuyuan_baoguoliebiao_item2_t2'"
						@tap="dianji" data-id="1">
						{{ $t('page_indexs_dairuku.not_in_storage') }}({{ total.nocount }})
					</view> -->
					<!-- 2 已入库 -->
					<view
						:class="dianjis == 2 ? 'cangkuyuan_baoguoliebiao_item2_t1' : 'cangkuyuan_baoguoliebiao_item2_t2'"
						@tap="dianji" data-id="2">
						{{ $t('page_indexs_dairuku.stocked') }}({{ total.yescount }})
					</view>
					<!-- 4 待打包 -->
					<view
						:class="dianjis == 4 ? 'cangkuyuan_baoguoliebiao_item2_t1' : 'cangkuyuan_baoguoliebiao_item2_t2'"
						@tap="dianji" data-id="4">
						{{ $t('page_indexs_dairuku.tobodabao') }}({{ total.daidabao }})
					</view>
					<!-- 5 待支付 -->
					<view
						:class="dianjis == 5 ? 'cangkuyuan_baoguoliebiao_item2_t1' : 'cangkuyuan_baoguoliebiao_item2_t2'"
						@tap="dianji" data-id="5">
						{{ $t('page_indexs_dairuku.daizhifu') }}({{ total.daizhifu }})
					</view>
					<!-- 8 待发货 -->
					<view
						:class="dianjis == 8 ? 'cangkuyuan_baoguoliebiao_item2_t1' : 'cangkuyuan_baoguoliebiao_item2_t2'"
						@tap="dianji" data-id="8">
						{{ $t('page_indexs_dairuku.daifahuo') }}({{ total.daifahuo }})
					</view>
					<!-- 9 已发货 -->
					<view
						:class="dianjis == 9 ? 'cangkuyuan_baoguoliebiao_item2_t1' : 'cangkuyuan_baoguoliebiao_item2_t2'"
						@tap="dianji" data-id="9">
						{{ $t('page_indexs_dairuku.yifahuo') }}({{ total.yetsend }})
					</view>
					<!-- 10 已收货 -->
					<view
						:class="dianjis == 10 ? 'cangkuyuan_baoguoliebiao_item2_t1' : 'cangkuyuan_baoguoliebiao_item2_t2'"
						@tap="dianji" data-id="10">
						{{ $t('page_indexs_dairuku.yijingshouhuo') }}({{ total.yishouhuo }})
					</view>
					<!-- 11 已收货 -->
					<view
						:class="dianjis == 11 ? 'cangkuyuan_baoguoliebiao_item2_t1' : 'cangkuyuan_baoguoliebiao_item2_t2'"
						@tap="dianji" data-id="11">
						{{ $t('page_indexs_dairuku.yijingqianshou') }}({{ total.yijingqianshou }})
					</view>
					<!-- -1 问题件 -->
					<view
						:class="dianjis == -1 ? 'cangkuyuan_baoguoliebiao_item2_t1' : 'cangkuyuan_baoguoliebiao_item2_t2'"
						@tap="dianji" data-id="-1">
						{{ $t('page_indexs_dairuku.problem_piece') }}({{ total.procount }})
					</view>
				</view>
				<view class="search">
					<view class="search-box">
						<image :src="imgUrl + '/dzx_img38.png'"></image>
						<input type="text" :placeholder="$t('page_indexs_dairuku.please_enter_the_parcel_number')"
							@input="search" @confirm="huiche" />
					</view>
				</view>
				<view class="dairuku_list" v-if="arrlist.length != 0">
					<view class="dairuku_cont" v-for="(item, index) in arrlist" :key="index">
						<view class="dairuku_top">
							<view class="dairuku_top_l">
								<image :src="imgUrl + '/dzx_img24.png'"></image>
								<text>{{ item.storage?item.storage.shop_name:'' }}</text>
							</view>
							<view class="dairuku_top_r" @tap="tiaozhuan" :data-id="item.id">
								<text>{{ $t('page_indexs_dairuku.check_the_details') }}</text>
								<image :src="imgUrl + '/dzx_img25.png'"></image>
							</view>
						</view>

						<view class="dairuku_top">
							<view class="dairuku_top_l">
								<image :src="imgUrl + '/dzx_img27.png'"></image>
								<text>{{ $t('page_indexs_dairuku.parcel_no') }}：{{ item.express_num }}</text>
								<text style="color: #ff6600" v-if="item.source == 6">{{$t('page_other.拼')}}</text>
								<view class="cangkudizhi_item1_t3" @tap="fuzhi" :data-name="item.express_num">
									（{{ $t('page_indexs_dairuku.copy_tracking_number') }}）</view>
							</view>
						</view>

						<view class="dairuku_center">
							<view class="dairuku_center_cont">
								<view class="dairuku_center_t1">{{ $t('page_indexs_dairuku.shipping_country') }}：</view>
								<view class="dairuku_center_t2">
									{{ item.country ? item.country.title : $t('page_indexs_dairuku.unknown') }}</view>
							</view>
							<view class="dairuku_center_cont" v-if="item.class_name">
								<view class="dairuku_center_t1">{{ $t('page_indexs_dairuku.item_information') }}：</view>
								<view class="dairuku_center_t2">{{ item.class_name }}</view>
							</view>
							<view class="dairuku_center_cont" v-if="item.usermark && setting.is_usermark==1">
								<view class="dairuku_center_t1">{{ $t('page_indexs_dairuku.usermark') }}：</view>
								<view class="dairuku_center_t2">{{ item.usermark }}</view>
							</view>
							<view class="dairuku_center_cont" v-if="item.inpack !== null" @click="chakanxq(item.inpack.id)">
								<view class="dairuku_center_t1">{{ $t('page_indexs_dairuku.order_sn') }}：</view>
								<view class="dairuku_center_t2" style="color:#4ad5ac">
									{{ item.inpack?item.inpack.order_sn : '' }}</view>
							</view>
							<view class="dairuku_center_cont">
								<view class="dairuku_center_t1">{{ $t('page_indexs_dairuku.reporting_time') }}：</view>
								<view class="dairuku_center_t2">{{ item.created_time }}</view>
							</view>
							<view class="cangkuyuan_baoguoliebiao_item3_w1 pcicang" v-if="item.packageimage != ''">
								<view class="baoguopic">{{ $t('page_indexs_dairuku.package_image') }}：</view>
								<!-- <text @click="previewImage">查看图片</text> -->
								<view class="index_item5_cont_bottom_img" :data-url="item" @click="previewImage">
									<view class="index_item5_cont_bottom_imgs"
										v-for="(items, index1) in item.packageimage" :key="index1" :data-url="items"
										:data-index="index1" @click="getIndex">
										<image :src="items.file_path" mode="aspectFill"></image>
									</view>
								</view>
							</view>
						</view>

						<view class="dairuku_bottom">
							<view class="dairuku_bottom_btn1" v-if="item.status == 1 || item.status == 2"
								@tap="quxiaoshenqing" :data-id="item.id">
								{{ $t('page_indexs_dairuku.cancel_forecast') }}
							</view>
							<view class="dairuku_bottom_btn1" v-if="item.status == 1 || item.status == 2"
								@tap="xiugaishenqing" :data-id="item.id">
								{{ $t('page_indexs_dairuku.revised_forecast') }}
							</view>
							<view class="dairuku_bottom_btn2" @tap="wuliu" :data-id="item.express_num">
								{{ $t('page_indexs_dairuku.check_logistics') }}</view>
							<view class="dairuku_bottom_btn2" v-if="item.status == -1" @tap="rechangePackage"
								:data-id="item">
								{{ $t('page_indexs_dairuku.recovery_forecast') }}
							</view>
							<!-- 预留功能，暂未实现 -->
							<!-- <view class="dairuku_bottom_btn2" v-if="item.status == -1" @tap="rechangePackage" :data-id="item">申请退件</view> -->
						</view>
					</view>
				</view>
				<view class="my_dingdan_zanwu" v-else>
					<image :src="imgUrl + '/dzx_img43.png'"></image>
					<text>{{ $t('page_indexs_dairuku.no_package_yet') }}</text>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	// pages/shouye/shouye_zkc/shouye_zkc.js
	const app = getApp();

	let request = require('../../../utils/require');

	export default {
		data() {
			return {
				navH: app.globalData.navHeight,
				gaodu: app.globalData.height,
				gaodutops: app.globalData.top,
				imgUrl: app.globalData.imgUrl,
				setting:'',
				//分页
				page: 1,
				ispage: true,
				arrlist: [],
				artimages: [],
				imgindex: 0,
				index1: 0,
				dianjis: 2,
				total: {
					nocount: 0,
					yescount: 0,
					procount: 0,
					daidabao:0,
					daizhifu:0,
					daifahuo:0,
					yetsend:0,
					yishouhuo:0,
				}
			};
		},
		/**
		 * 生命周期函数--监听页面加载
		 */
		onLoad() {
			var that = this;
			that.dairukulist();
			that.countpack();
		},
		onShow() {
			var that = this;
			that.settingFun();
			that.page = 1
			that.ispage = true
		},
		/**
		 * 生命周期函数--监听页面初次渲染完成
		 */
		onReady: function() {},
		/**
		 * 生命周期函数--监听页面隐藏
		 */
		onHide: function() {},
		/**
		 * 生命周期函数--监听页面卸载
		 */
		onUnload: function() {},
		/**
		 * 页面相关事件处理函数--监听用户下拉动作
		 */
		onPullDownRefresh: function() {},
		/**
		 * 页面上拉触底事件的处理函数
		 */
		onReachBottom: function() {
			if (this.ispage) {
				this.page = this.page + 1
				this.dairukulist();
			}
		},
		/**
		 * 用户点击右上角分享
		 */
		onShareAppMessage: function() {},
		methods: {
			//设置
			settingFun() {
				var that = this;
				var data = {
					token: uni.getStorageSync('token')
				};
				request.post(`index.php?s=/api/page/service&wxapp_id=` + uni.getStorageSync('web_id'), data).then(res => {
					if (res.data.code == 1) {
						that.setting = res.data.data.values;
						uni.setStorageSync('setting', res.data.data.values);
						uni.setStorageSync('paytype', res.data.data.paytype);
						uni.setStorageSync('copyright', res.data.data.copyright);
						uni.setStorageSync('userclient', res.data.data.userclient);
						uni.setStorageSync('weight_mode', res.data.data.values.weight_mode);
						uni.setStorageSync('price_mode', res.data.data.values.price_mode);
						uni.setStorageSync('appname', res.data.data.values.name);
						uni.setStorageSync('is_packagestation', res.data.data.values.is_packagestation);
						uni.setStorageSync('is_categorysearch', res.data.data.values.is_categorysearch);
						uni.setStorageSync('address_setting', res.data.data.values.address_setting);
						uni.setStorageSync('menu_type', res.data.data.values.menu_type);
					} else {
						uni.showToast({
							title: res.data.msg,
							icon: 'none'
						});
					}
				});
			},
			chakanxq(e) {
				uni.navigateTo({
					url: '/pages/indexs/my_dingdan_details/my_dingdan_details?id=' + e
				});
			},
			//复制
			fuzhi: function(e) {
				var that = this;
				uni.setClipboardData({
					data: e.currentTarget.dataset.name,
					success: function(res) {
						uni.getClipboardData({
							success: function(res) {
								uni.showToast({
									title:that.$t('page_other.复制成功')
								});
							}
						});
					}
				});
			},
			dianji(e) {
				this.dianjis = e.currentTarget.dataset.id;
				this.arrlist = []
				this.page = 1
				this.ispage = true
				this.dairukulist();
			},
			huiche(e) {
				this.ispage == false;
				this.searchlist(e.detail.value);
			},
			search(e) {
				console.log(e.detail.value, 6677);
				if (e.detail.value == '') {
					this.arrlist = []
					this.dairukulist();
				}
			},
			wuliu(e) {
				uni.navigateTo({
					url: '/pages/chaxun/chaxun?id=' + e.currentTarget.dataset.id
				});
			},

			//修改申请
			xiugaishenqing(e) {
				uni.navigateTo({
					url: '/pages/indexs/dairuku_xgxx/dairuku_xgxx?id=' + e.currentTarget.dataset.id
				});
			},
			previewImage(e) {
				var len = e.currentTarget.dataset.url.packageimage.length;
				console.log(len, 88888);
				var artimages = this.artimages;
				for (var i = 0; i < len; i++) {
					artimages[i] = e.currentTarget.dataset.url.packageimage[i].file_path;
				}
				uni.previewImage({
					current: this.imgindex,
					urls: this.artimages
				});
			},
			getIndex(e) {
				this.imgindex = e.currentTarget.dataset.index
			},
			//恢复包裹状态
			rechangePackage(e) {
				var that = this;
				var data = {
					token: uni.getStorageSync('token'),
					id: e.currentTarget.dataset.id.id,
					express_num: e.currentTarget.dataset.id.express_num
				};
				uni.showModal({
					title:that.$t('page_other.提示'),
					content:that.$t('page_other.订单将会恢复预报状态') ,
					success(res) {
						if (res.confirm) {
							request.post(`index.php?s=/api/package/rechangePackage&wxapp_id=` + uni.getStorageSync(
								'web_id'), data).then(res => {
								if (res.data.code == 1) {
									uni.showToast({
										title: res.data.data
									});
									setTimeout(() => {
										that.arrlist = []
										that.page = 1
										that.ispage = true
										that.dairukulist(that.dianjis);
									}, 1000);
								} else {
									uni.showToast({
										title: res.data.msg,
										icon: 'none'
									});
								}
							});
						} else {
							if (res.cancel) {}
						}
					}
				});
			},
			//取消申请
			quxiaoshenqing(e) {
				var that = this;
				var data = {
					token: uni.getStorageSync('token'),
					id: e.currentTarget.dataset.id
				};
				uni.showModal({
					title: that.$t('page_other.提示'),
					content: that.$t('page_other.是否确认取消预报'),
					success(res) {
						if (res.confirm) {
							request.post(`index.php?s=/api/package/cancle&wxapp_id=` + uni.getStorageSync(
								'web_id'), data).then(res => {
								if (res.data.code == 1) {
									uni.showToast({
										title: res.data.data
									});
									setTimeout(() => {
										that.arrlist = []
										that.dairukulist();
									}, 1000);
								} else {
									uni.showToast({
										title: res.data.msg,
										icon: 'none'
									});
								}
							});
						} else {
							if (res.cancel) {}
						}
					}
				});
			},

			tiaozhuan(e) {
				uni.navigateTo({
					url: '/pages/indexs/dairuku_xq/dairuku_xq?id=' + e.currentTarget.dataset.id
				});
			},

			jumpzuo() {
				uni.navigateBack();
			},

			dairukulist() {
				var that = this;
				var data = {
					token: uni.getStorageSync('token'),
					page: that.page,
					status: that.dianjis
				};
				if(uni.getStorageSync("usermark")){
					data['usermark'] = uni.getStorageSync("usermark").mark;
				}
				request.get(`index.php?s=/api/package/outside&wxapp_id=` + uni.getStorageSync('web_id'), data).then(
				res => {
					if (res.data.code == 1) {
						if (that.page > res.data.data.last_page) {
							that.ispage= false
						} else {
							that.arrlist = that.arrlist.concat(res.data.data.data)
						}
						console.log(res, 're??');
					}
				});
			},
			searchlist(e) {
				var that = this;
				var data = {
					token: uni.getStorageSync('token'),
					status: that.dianjis,
					keyword: e
				};
				request.get(`index.php?s=/api/package/searchList&wxapp_id=` + uni.getStorageSync('web_id'), data).then(
					res => {
						if (res.data.code == 1) {
							that.arrlist = res.data.data.data
						}
					});
			},

			countpack() {
				var that = this;
				var data = {
					token: uni.getStorageSync('token')
				};
				if(uni.getStorageSync("usermark")){
					data['usermark'] = uni.getStorageSync("usermark").mark;
				}
				request.get(`index.php?s=/api/package/countpack&wxapp_id=` + uni.getStorageSync('web_id'), data).then(
					res => {
						if (res.data.code == 1) {
							console.log(res.data.data, 65656);
							that.total = res.data.data
						}
					});
			}
		}
	};
</script>
<style>
	@import './dairuku.css';
</style>